package com.ziguang.redwood.web.service;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

public class WebHomeService {
	private static final Logger log = LoggerFactory.getLogger(WebHomeService.class);

	public static final WebHomeService me = new WebHomeService();
	
	/**
	 * 查询首页图片
	 * @return
	 */
	public List<Record> findHomeImg(){
		List<Record> topImg = Db.find("select * from rw_home order by sort");
		return topImg;
	}
	
	/**
	 * 查询分类图片/产品图片
	 * @return
	 */
	public List<Record> findProduct(){
		List<Record> productTypeList = Db.find
				("SELECT t.type_name,t.type_img,p.*,MAX(p.sort) FROM rw_product p LEFT JOIN rw_product_type t ON p.type_id = t.id GROUP BY t.sort");
		for(Record a : productTypeList){
			int id = a.get("type_id");
			List<Record> productList = Db.find
					("SELECT t.type_name,t.type_img,p.* FROM rw_product p LEFT JOIN rw_product_type t ON p.type_id = t.id WHERE t.id = ? order by p.sort limit 4",id);
			a.set("productList", productList);
		}
		return productTypeList;
	}
	
	
}
